/*The following codes are prepared for Corporate Climate Risk: Measurements and Responses (Li, Shan, Tang and Vincent 2023)*/

/*Figures*/
/*Figure 1*/
preserve	
collapse (mean) phy_risk_acute_w_std phy_risk_chronic_w_std tran_risk_w_std, by(qtrnum)
sum 
restore

preserve	
keep if tran_risk_w > 0
keep gvkey
gen firm_tran_risk = 1
duplicates drop gvkey, force
sort gvkey
save firm_tran_risk, replace
restore
 
sort gvkey
merge n:1 gvkey using firm_tran_risk
drop if _merge==2
drop _merge
replace firm_tran_risk = 0 if firm_tran_risk == .
tab firm_tran_risk
 
preserve	
collapse (mean) tran_risk_pro_w_std tran_risk_npro_w_std if firm_tran_risk == 1, by(qtrnum)
sum 
restore
 
/*Figure 2*/
egen region_state = concat(region state), punct(_) 
gen region_exl = 1 if inlist(state,"PR", "VI")
tab region_state if region_exl != 1, gen(reg_st_)
tab naics2, gen(naics2_)
eststo: quietly reghdfe phy_risk_acute_w_std  naics2_* reg_st_* if region_exl != 1, a(  qtrnum ) 
eststo: quietly reghdfe phy_risk_chronic_w_std  naics2_* reg_st_* if region_exl != 1, a(  qtrnum ) 
eststo: quietly reghdfe tran_risk_w_std   naics2_* reg_st_* if region_exl != 1, a(  qtrnum ) 
eststo: quietly reghdfe tran_risk_pro_w_std naics2_* reg_st_* if region_exl != 1 & firm_tran_risk == 1, a(  qtrnum ) 
 
 
/*Figure 3*/
label var tran_risk_w_std "Transition Risk"
label var cl_msci_std "MSCI Climate Change Score"
binscatter tran_risk_w_std cl_msci_std if firmyq_msci == 1, nquantiles(50)
preserve	
keep if naics2 == 33 
sort naics
collapse (mean) tran_risk_w_std co2_rate_direct, by(naics)
binscatter co2_rate_direct tran_risk_w_std, nquantiles(30)

 
/*Tables*/
/*Table 1: Summary of Statistics*/
tabstat phy_risk_acute_w phy_risk_chronic_w tran_risk_w tran_risk_pro_w tran_risk_npro_w energypriceindex_w actionindex_w tobin_q_w capx_ta_w rd_w_b logatq_lag_w ppe_lag_w bk_leverage_lag_w num_analysts_log instown_perc instown_hhi roaq_lag_w if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat disaster_hq_county if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat logemp_lead1 if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat greenp_wo1_ratio_file dgreenp if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat news_scale_w if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
winsor cl_score, p(.001) gen(cl_score_w) 
winsor cl_exp, p(.001) gen(cl_exp_w) 
gen cl_msci=(10-cl_score_w)*cl_exp_w
tabstat cl_msci erri_w enscore_w if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat tran_risk_mda_w if naics2 != 52,  s(count mean sd min p25 p50 p75 max)
tabstat tran_risk_rfactors_w if naics2 != 52 & year>=2006,  s(count mean sd min p25 p50 p75 max)
foreach var in news_scale {
	winsor `var', generate(`var'_w) p(.001)
}
/*Table 4*/
/*Panel A*/
global depvar "phy_risk_acute_w_std phy_risk_chronic_w_std"
global num  "_determin_1"
global disaster_hit "disaster_hq_county_lag"
global disaster_hit4 "disaster_hq_county_lag disaster_hq_county_lag2 disaster_hq_county_lag3  disaster_hq_county_lag4"
global control_set1 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w num_analysts_log instown_perc instown_hhi"

foreach var in $depvar { 
  
reghdfe `var' $disaster_hit $control_set1  if  naics2 != 21, a(indqtr) vce(cluster gvkey)
outreg2 using Table 4_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append
 
reghdfe `var' $disaster_hit4 $control_set1  if  naics2 != 21, a(indqtr) vce(cluster gvkey)
outreg2 using Table 4_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append

}

/*Panel B*/
global depvar "tran_risk_w_std tran_risk_pro_w_std tran_risk_npro_w_std"
foreach var in $depvar { 
  
reghdfe `var' cl_msci $control_set1 if naics2 != 52, a(indqtr) vce(cluster gvkey)
outreg2 using Table 4_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append
 
reghdfe `var' cl_msci $control_set1 if naics2 != 52, a(indqtr) vce(cluster gvkey)
outreg2 using Table 4_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append

}


/*Panel C*/
global depvar "emission_over_at_lead1 emission_over_at_lead2 emission_over_at_lead3 emission_over_at_lead4 emission_over_at_lead5"
foreach var in $depvar { 
   
reghdfe `var' tran_risk_w_year_std logatq_lag_w_year if naics2 != 52, a(indyear) vce(cluster gvkey)
outreg2 using Table 4_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append
 
reghdfe `var' tran_risk_pro_w_year_std tran_risk_npro_w_year_std logatq_lag_w_year if naics2 != 52, a(indyear) vce(cluster gvkey)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using Table 4_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a), C3 F, `p1') append

}	
/*Table 5*/
/*Panel A*/
egen loc2_yr_fe = group(qtrnum state)
egen loc1_fe = group(state)
egen loc2_fe = group(cnty_fips5)
gen one = 1
foreach var in phy_risk_acute_w_std phy_risk_chronic_w_std tran_risk_w_std  {
 eststo: quietly reghdfe `var' one, a( qtrnum)
 eststo: quietly reghdfe `var' one, a( qtrnum loc1_fe)
 eststo: quietly reghdfe `var' one, a( qtrnum loc2_fe)
 eststo: quietly reghdfe `var' one, a( qtrnum naics2)
 eststo: quietly reghdfe `var' one, a( qtrnum naics3)
 eststo: quietly reghdfe `var' one, a( qtrnum naics4)
 eststo: quietly reghdfe `var' one, a( qtrnum loc1_fe naics2)
 eststo: quietly reghdfe `var' one, a( ind1_yr_fe loc1_fe)
 eststo: quietly reghdfe `var' one, a( naics2 loc2_yr_fe)
 eststo: quietly reghdfe `var' one, a( ind1_yr_fe loc2_yr_fe)
 eststo: quietly reghdfe `var' one, a( ind1_yr_fe loc1_yr_fe)
 eststo: quietly reghdfe `var' one, a( qtrnum gvkey)
 eststo: quietly reghdfe `var' one $control_set1, a( qtrnum gvkey)
 eststo: quietly reghdfe `var' one $control_set1, a( ind1_yr_fe gvkey)
 eststo: quietly reghdfe `var' one $control_set1, a( loc2_yr_fe gvkey)
esttab using Table 5_A.csv, append beta not b(3) t(2) nose nogap ar2 scalar(r2_p) star(* 0.10 ** 0.05 *** 0.01) label title(R2) 
eststo clear
}

/*Panel B*/
global depvar "phy_risk_acute_w_std phy_risk_chronic_w_std tran_risk_w_std"  
foreach var in $depvar { 
reghdfe `var'  $control_set1 if naics2 != 52, a(indqtr) vce(cluster gvkey)
outreg2 using Table 5_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append
}

global depvar "tran_risk_pro_w_std"
global control_set1 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w num_analysts_log instown_perc instown_hhi tran_risk_w_std"
foreach var in $depvar { 
 
reghdfe `var' $control_set1 if  naics2 != 52, a(indqtr) vce(cluster gvkey)
outreg2 using Table 5_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(R-squared, e(r2_a)) append
}


/*Table 6 - Panel A*/
global depvar "tobin_q_w"
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"

foreach yvar in tobin_q_w {
foreach vart in 1 3 5 { 

reghdfe `yvar'_`vart' $regressor1 $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table6_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N, include utility, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append

}
}

foreach yvar in tobin_q_w {
foreach vart in 1 3 5 { 

reghdfe `yvar'_`vart' $regressor9 $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table6_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N, include utility, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

}
}

/*Table 6 - Panel B*/
foreach yvar in tobin_q_w {
foreach vart in 1 { 

reghdfe `yvar'_`vart' $regressor1 $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22  & year<2010, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table6_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append

reghdfe `yvar'_`vart' $regressor1 $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22 & year>=2010, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table6_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append

reghdfe `yvar'_`vart' $regressor9 $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 & year<2010, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table6_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

reghdfe `yvar'_`vart' $regressor9 $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 & year>=2010, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table6_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}



/*Table 7 */
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"

foreach var in cc_expo ph_cc_expo op_cc_expo rg_cc_expo tran_risk_mda tran_risk_rfactors {

egen `var'_sd=sd(`var')
gen `var'_std=`var'/`var'_sd

}
/*Table 7A*/
foreach var in 1  5 { 

reghdfe tobin_q_w_`var' $regressor1 tran_risk_mda_std $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22 , a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append
}
foreach var in 1  5 { 

reghdfe tobin_q_w_`var' $regressor1 tran_risk_rfactors_std $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22 & fyear>=2006, a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append
}
foreach var in 1 5{ 

reghdfe tobin_q_w_`var' $regressor9 tran_risk_mda_std $control_set2 energypriceindex_std actionindex_std if naics2 != 52& naics2 != 22 , a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append
}
foreach var in 1 5{ 

reghdfe tobin_q_w_`var' $regressor9 tran_risk_rfactors_std $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 & fyear>=2006 , a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append
}

/*Table 7B*/
clear
use ravenpack_75
global depvar "tobin_q_w"
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"
sort gvkey quarter
foreach var in news_scaled{

egen `var'_sd=sd(`var')
gen `var'_std=`var'/`var'_sd

}
foreach yvar in tobin_q_w {
foreach vart in 1 5{ 

reghdfe `yvar'_`vart' $regressor1 news_scaled_std $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table7_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append
}
}
foreach yvar in tobin_q_w {
foreach vart in 1 5{ 

reghdfe `yvar'_`vart' $regressor9 news_scaled_std $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 , a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table7_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}
************************
clear
use ravenpack_50
global depvar "tobin_q_w"
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"
sort gvkey quarter

foreach var in news_scaled{

egen `var'_sd=sd(`var')
gen `var'_std=`var'/`var'_sd

}

foreach yvar in tobin_q_w {
foreach vart in 1 5{ 

reghdfe `yvar'_`vart' $regressor1 news_scaled_std $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table7_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append
}
}
foreach yvar in tobin_q_w {
foreach vart in 1 5{ 

reghdfe `yvar'_`vart' $regressor9 news_scaled_std $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table7_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}


/*Table 7C*/
global depvar "tobin_q_w"
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"

foreach yvar in tobin_q_w {
foreach vart in 1 5 { 

reghdfe `yvar'_`vart' $regressor1 $control_set2 cl_msci_std energypriceindex_std  if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table7_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

reghdfe `yvar'_`vart' $regressor1 $control_set2 energypriceindex_std if naics2 != 52 & naics2 != 22 & cl_msci_std ==., a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table7_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

}
}

foreach yvar in tobin_q_w {
foreach vart in 1 5 { 

reghdfe `yvar'_`vart' $regressor9 $control_set2 cl_msci_std energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table7_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

reghdfe `yvar'_`vart' $regressor9 $control_set2 energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 & cl_msci_std ==., a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table7_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}




/*Table 7D first four columns*/
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"
foreach var in cc_expo ph_cc_expo op_cc_expo rg_cc_expo tran_risk_mda tran_risk_rfactors {

egen `var'_sd=sd(`var')
gen `var'_std=`var'/`var'_sd

}

foreach var in 1 5{ 

reghdfe tobin_q_w_`var' $regressor1 cc_expo_std energypriceindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_D, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

}
foreach var in 1 5{ 

reghdfe tobin_q_w_`var' $regressor9 ph_cc_expo_std op_cc_expo_std rg_cc_expo_std energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_D, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

}

/*Table 7D columns 5 and 6*/
foreach var in 1 { 

reghdfe tobin_q_w_`var' $regressor1 cc_expo_std energypriceindex_std if naics2 != 52 & fyear>=2010 & naics2 != 22, a(indqtr) vce(cluster qtrnum gvkey)
outreg2 using table7_D, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

}
foreach var in 1 { 

reghdfe tobin_q_w_`var' $regressor9 ph_cc_expo_std op_cc_expo_std rg_cc_expo_std energypriceindex_std actionindex_std if naics2 != 52 & fyear>=2010 & naics2 != 22, a(indqtr) vce(cluster qtrnum gvkey)
test tran_risk_npro_w_std=rg_cc_expo_std
local p1=r(p)
outreg2 using table7_D, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Test1 F, `p1') append

}



/*Table 8 tobin Q firm FE*/
global depvar "tobin_q_w"
global control_set2 "logatq_lag_w capex_m_lag_w ppe_lag_w bk_leverage_lag_w roaq_lag_w"
global regressor1 "tran_risk_w_std"
global regressor9 "tran_risk_npro_w_std tran_risk_pro_w_std"

sort gvkey qtrnum
by gvkey: gen chg_tran_risk_npro_w_std1 = tran_risk_npro_w_std[_n] - tran_risk_npro_w_std[_n-1] 
by gvkey: gen chg_tran_risk_pro_w_std1 = tran_risk_pro_w_std[_n] - tran_risk_pro_w_std[_n-1] 
by gvkey: gen chg_tran_risk_w_std1 = tran_risk_w_std[_n] - tran_risk_w_std[_n-1] 
by gvkey: gen tobin_q_w_n1 = tobin_q_w[_n-1]
by gvkey: gen chg_tobin_q_w_1 = tobin_q_w[_n+1] - tobin_q_w[_n]
by gvkey: gen chg_tobin_q_w_2 = tobin_q_w[_n+2] - tobin_q_w[_n]
by gvkey: gen chg_tobin_q_w_3 = tobin_q_w[_n+3] - tobin_q_w[_n]
by gvkey: gen chg_tobin_q_w_4 = tobin_q_w[_n+4] - tobin_q_w[_n]
by gvkey: gen chg_tobin_q_w_5 = tobin_q_w[_n+5] - tobin_q_w[_n]
by gvkey: gen chg_tobin_q_w_6 = tobin_q_w[_n+6] - tobin_q_w[_n]

foreach yvar in chg_tobin_q_w {
foreach vart in 1 2 3 4 5 6 { 

reghdfe `yvar'_`vart' chg_tran_risk_w_std1 tobin_q_w_n1  $control_set2 energypriceindex_std if naics2 != 52 , a(indqtr gvkey) vce(cluster gvkey qtrnum)
outreg2 using table8_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(Firm Attributes, Y, indqtr FE, Y, Firm FE, Y) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append
}
}

foreach yvar in chg_tobin_q_w {
foreach vart in 1 2 3 4 5 6 { 

reghdfe `yvar'_`vart' chg_tran_risk_npro_w_std1 chg_tran_risk_pro_w_std1 tobin_q_w_n1 $control_set2 energypriceindex_std actionindex_std if naics2 != 52 , a(indqtr gvkey) vce(cluster gvkey qtrnum)
outreg2 using table8_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(Firm Attributes, Y, indqtr FE, Y, Firm FE, Y) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append

}
}


/*Table 9 CAPX*/
foreach yvar in capx_ta_w {
foreach vart in 1 3 5 { 


reghdfe `yvar'_`vart' $regressor1 logatq_lag_w energypriceindex_std if naics2 != 52 & naics2 != 22 , a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table9, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N, include utility, Y) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append
}
}

foreach yvar in capx_ta_w {
foreach vart in 1 3 5 { 


reghdfe `yvar'_`vart' $regressor9 logatq_lag_w energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table9, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(indqtr FE, Y, Firm FE, N, include utility, N) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}



/*Table 10 Predicting Firm's Other Responses */
/*Table 10 - Panel A*/
foreach yvar in  rd_w_b {
foreach vart in 1 3 5 { 


reghdfe `yvar'_`vart' $regressor1 logatq_lag_w energypriceindex_std if naics2 != 52 & naics2 != 22, a(indqtr) vce(cluster gvkey qtrnum)
outreg2 using table10_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))append
}
}
foreach yvar in  rd_w_b {
foreach vart in 1 3 5 { 


reghdfe `yvar'_`vart' $regressor9 logatq_lag_w energypriceindex_std actionindex_std if naics2 != 52 & naics2 != 22 , a(indqtr) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_std=tran_risk_pro_w_std
local p1=r(p)
outreg2 using table10_A, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append
}
}

/*Table 10 - Panel B*/
foreach var in tran_risk_w_year tran_risk_npro_w_year tran_risk_pro_w_year energypriceindex_year actionindex_year{

egen `var'_sd=sd(`var')
gen `var'_std=`var'/`var'_sd

}

sort gvkey year
foreach var in greenp_all_sum_file greenp_ratio_file { 
by gvkey: gen `var'_1 = `var'[_n+1]
by gvkey: gen `var'_2 = `var'[_n+2]
}		
gen dgreenp_1=(greenp_all_sum_file_1>0)
gen dgreenp_2=(greenp_all_sum_file_2>0)


/*Table 10 panel B column 1 2 3 4*/	
foreach var in dgreenp { 

reghdfe `var'_1 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22 , a(indyear) vce(cluster gvkey year)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))

reghdfe `var'_2 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22 , a(indyear) vce(cluster gvkey year)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))


reghdfe `var'_1 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22 , a(indyear) vce(cluster gvkey year)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

reghdfe `var'_2 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22 , a(indyear) vce(cluster gvkey year)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

}


/*Table 10 Panel B column 5 6 7 8*/	
foreach var in greenp_ratio_file { 

reghdfe `var'_1 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey year)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))

reghdfe `var'_2 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey year)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a))

reghdfe `var'_1 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey year)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

reghdfe `var'_2 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey year)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_B, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), Difference F, `p1') append

}
/*Table 10 - Panel C*/
gen logemp_lead1=log(1+emp_lead1)
gen logemp_lead2=log(1+emp_lead2)
reghdfe logemp_lead1 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey qtrnum)
outreg2 using table10_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes addtext(naics3*year FE, Y) tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append
reghdfe logemp_lead2 tran_risk_w_year_std logatq_lag_w_year energypriceindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey qtrnum)
outreg2 using table10_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a)) append

reghdfe logemp_lead1 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), C3 F, `p1') append
reghdfe logemp_lead2 tran_risk_npro_w_year_std tran_risk_pro_w_year_std logatq_lag_w_year energypriceindex_year_std actionindex_year_std if naics2 != 52 & naics2 != 22, a(indyear) vce(cluster gvkey qtrnum)
test tran_risk_npro_w_year_std=tran_risk_pro_w_year_std
local p1=r(p)
outreg2 using table10_C, excel stats(coef tstat) alpha(0.01, 0.05, 0.1) symbol(***, **, *) nonotes tdec(3) rdec(3) bdec(4) addstat(Adj R-squared, e(r2_a), C3 F, `p1') append


/*The End*/
